import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
// 设置swagger
import {SwaggerModule,DocumentBuilder} from '@nestjs/swagger'
import { Response } from './interceptors/response.interceptor';
// 注册全局异常过滤器
import { HttpFilter } from './filters/error.filter';
// 跨域处理
import * as cors from 'cors'
import { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path'
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  // 处理跨域中间件
  app.use(cors())
  // 设置swagger
  const option=new DocumentBuilder().setTitle('博客项目').build()
  const document=SwaggerModule.createDocument(app,option)
  SwaggerModule.setup('/api-docs',app,document)
  // 注册相应拦截器
  app.useGlobalInterceptors(new Response())
  // 注册全局异常过滤器
  app.useGlobalFilters(new HttpFilter)
  // 生成静态图片目录地址
  app.useStaticAssets(join(__dirname,'assets/img'),{
    prefix:'/assets/img'
  })
  await app.listen(3000);
}
bootstrap();
